package com.xbzl.cly_demo.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.Objects;

@TableName(value = "vehicle")
public class Vehicle implements Serializable {
    @TableId(value = "vehicle_id", type = IdType.AUTO)
    private Long vehicleId;

    @TableField(value = "vin")
    private String vin;

    @TableField(value = "device_name")
    private String deviceName;

    @TableField(value = "plate_no")
    private String plateNo;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    public Vehicle() {}

    public Vehicle(Long vehicleId, String vin, String deviceName, String plateNo) {
        this.vehicleId = vehicleId;
        this.vin = vin;
        this.deviceName = deviceName;
        this.plateNo = plateNo;
    }

    public Long getVehicleId() {
        return vehicleId;
    }

    public void setVehicleId(Long vehicleId) {
        this.vehicleId = vehicleId;
    }

    public String getVin() {
        return vin;
    }

    public void setVin(String vin) {
        this.vin = vin;
    }

    public String getDeviceName() {
        return deviceName;
    }

    public void setDeviceName(String deviceName) {
        this.deviceName = deviceName;
    }

    public String getPlateNo() {
        return plateNo;
    }

    public void setPlateNo(String plateNo) {
        this.plateNo = plateNo;
    }

    // ===== builder 方法 =====
    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {
        private Long vehicleId;
        private String vin;
        private String deviceName;
        private String plateNo;

        public Builder vehicleId(Long vehicleId) {
            this.vehicleId = vehicleId;
            return this;
        }

        public Builder vin(String vin) {
            this.vin = vin;
            return this;
        }

        public Builder deviceName(String deviceName) {
            this.deviceName = deviceName;
            return this;
        }

        public Builder plateNo(String plateNo) {
            this.plateNo = plateNo;
            return this;
        }

        public Vehicle build() {
            return new Vehicle(vehicleId, vin, deviceName, plateNo);
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Vehicle)) return false;
        Vehicle vehicle = (Vehicle) o;
        return Objects.equals(vehicleId, vehicle.vehicleId) &&
                Objects.equals(vin, vehicle.vin) &&
                Objects.equals(deviceName, vehicle.deviceName) &&
                Objects.equals(plateNo, vehicle.plateNo);
    }

    @Override
    public int hashCode() {
        return Objects.hash(vehicleId, vin, deviceName, plateNo);
    }

    @Override
    public String toString() {
        return "Vehicle{" +
                "vehicleId=" + vehicleId +
                ", vin='" + vin + '\'' +
                ", deviceName='" + deviceName + '\'' +
                ", plateNo='" + plateNo + '\'' +
                '}';
    }
}
